<template>
    <el-dialog v-model="dialogVisible" :title="title" :width="width" :destroy-on-close="destroyOnClose"
        :draggable="true" :close-on-click-modal="false" :close-on-press-escape="false">
        <!-- 插槽 -->
        <slot></slot>
        <template #footer>
            <span class="dialog-footer">
                <el-button @click="close">取消</el-button>
                <el-button type="primary" @click="submit" :loading="btnLoading">
                    {{ confirmText }}
                </el-button>
            </span>
        </template>
    </el-dialog>
</template>


<script setup>
import { ref } from 'vue'

const dialogVisible = ref(false)
const btnLoading = ref(false)
//对外属性暴露
const props = defineProps({
    title: String,
    width: {
        type: String,
        default: '40%'
    },
    confirmText: {
        type: String,
        default: '提交'
    },
    destroyOnClose: {
        type: Boolean,
        default: false
    }
})
//对外暴露一个submit方法
const emit = defineEmits(['submit'])
const submit = () => emit('submit')
// 打开
const open = () => dialogVisible.value = true
// 关闭
const close = () => dialogVisible.value = false
const showBtnLoading = () => btnLoading.value = true
const hideBtnLoading = () => btnLoading.value = false

// 暴露给父组件
defineExpose({
    open,
    close,showBtnLoading,hideBtnLoading
})

</script>
